package com.lsh.payment.core.service.async.impl;

import com.google.common.eventbus.AllowConcurrentEvents;
import com.google.common.eventbus.Subscribe;
import com.lsh.payment.core.dao.redis.RedisListDao;
import com.lsh.payment.core.model.payasync.EmailModel;
import com.lsh.payment.core.service.async.IEventListener;
import com.lsh.payment.core.service.email.SendEmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Project Name: lsh-payment
 * @author by jingyuan
 * Date: 16/12/22
 * 北京链商电子商务有限公司
 * Package com.lsh.payment.core.service.AsyncService
 * desc:异步处理监听类
 */
@Component
public class EmailEventListener implements IEventListener {

    @Autowired
    private SendEmailService sendEmailService;

    @Autowired
    private RedisListDao redisListDao;

    /**
     * 发送邮件
     *
     * @param emailModel 监听类
     */
    @Subscribe
    @AllowConcurrentEvents
    public void sendEmail(EmailModel emailModel) {
        boolean emailFlag = sendEmailService.send(emailModel.getContent(), emailModel.getTitle(), emailModel.getToEmails());
//        if (!emailFlag) {
//            redisListDao.rightPush(RedisKeyConstant.EMAIL, emailModel.getContent());
//        }
    }

}
